package com.example.eduservice.controller;


import com.example.commonutils.Result;
import com.example.eduservice.entity.excel.SubjectData;
import com.example.eduservice.entity.subject.OneSubject;
import com.example.eduservice.service.EduSubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author Anticipate
 * @since 2022-03-12
 */
@RestController
@RequestMapping("/eduservice/subject")
@CrossOrigin // 跨域
@Api(description = "课程分类管理")
public class EduSubjectController {

    @Autowired
    private EduSubjectService eduSubjectService;

    // 添加课程分类
    // 获取上传过来的文件，把文件内容读出来
    @ApiOperation(value = "Excel导入")
    @PostMapping("/addSubject")
    public Result addSubject(MultipartFile file) {
        // 获取上传的excel文件 MultipartFile
        eduSubjectService.saveSubject(file, eduSubjectService);
        return Result.ok();
    }

    // 获取所有课程列表（树形）
    @ApiOperation(value = "获取课程信息列表（树形）")
    @GetMapping("getSubjectList")
    public Result getSubjectList() {
        // list集合泛型是一级分类
        ArrayList<OneSubject> list = new ArrayList<>();
        List<OneSubject> oneSubjectList = eduSubjectService.getSubjectList();

        return Result.ok().data("list", oneSubjectList);
    }

    // 分局一级分类id查询二级分类


}
